$(function () {
    function Base64() {

        // private property
        let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

        // public method for encoding
        this.encode = function (input) {
            var output = "";
            var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
            var i = 0;
            input = _utf8_encode(input);
            while (i < input.length) {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                    enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                    enc4 = 64;
                }
                output = output +
                    _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
                    _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
            }
            return output;
        }

        // public method for decoding
        this.decode = function (input) {
            var output = "";
            var chr1, chr2, chr3;
            var enc1, enc2, enc3, enc4;
            var i = 0;
            input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
            while (i < input.length) {
                enc1 = _keyStr.indexOf(input.charAt(i++));
                enc2 = _keyStr.indexOf(input.charAt(i++));
                enc3 = _keyStr.indexOf(input.charAt(i++));
                enc4 = _keyStr.indexOf(input.charAt(i++));
                chr1 = (enc1 << 2) | (enc2 >> 4);
                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                chr3 = ((enc3 & 3) << 6) | enc4;
                output = output + String.fromCharCode(chr1);
                if (enc3 != 64) {
                    output = output + String.fromCharCode(chr2);
                }
                if (enc4 != 64) {
                    output = output + String.fromCharCode(chr3);
                }
            }
            output = _utf8_decode(output);
            return output;
        }

        // private method for UTF-8 encoding
        let _utf8_encode = function (string) {
            string = string.replace(/\r/g,"");
            var utftext = "";
            for (var n = 0; n < string.length; n++) {
                var c = string.charCodeAt(n);
                if (c < 128) {
                    utftext += String.fromCharCode(c);
                } else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                } else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }

            }
            return utftext;
        }

        // private method for UTF-8 decoding
        let _utf8_decode = function (utftext) {
            var string = "";
            var i = 0;
            var c = 0;
            var c1 = 0;
            var c2 = 0;
            var c3 = 0;
            while ( i < utftext.length ) {
                c = utftext.charCodeAt(i);
                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                } else if((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i+1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                } else {
                    c2 = utftext.charCodeAt(i+1);
                    c3 = utftext.charCodeAt(i+2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }
            }
            return string;
        }
    }
    let base64 = new Base64();
    let whiteUrl = ['/crmPc/home/pcLoginCallBack'];

    $.extend({
        baseUrl: 'https://api.youdomain.com',
        // baseUrl: 'http://localhost:8081',
        // baseUrl: 'https://api.youdomain.com',
        base64: base64,
        uploadUrl:"https://api.youdomain.com/file/uploadObjectOSS",
        baseFileUrl: 'https://you-one-stand.oss-cn-shanghai.aliyuncs.com',
        cAjax: function (url, setting) {
            if (!setting) {setting = {data: {ignore: true}}}

            if (setting&&setting.data && !whiteUrl.includes(url)) {
                setting.data  = {
                    data: base64.encode(JSON.stringify(setting.data)),
                }
            }

            let companyKey = localStorage.getItem('company_key');

            var _this = this;
            return new Promise(function(resolve, reject) {
                var _url = url.startsWith('http') ? url : _this.baseUrl + url;
                var baseSetting = {
                    type: 'POST',
                    headers: {
                        token: localStorage.getItem('token') || '',
                        'Content-Type':  'application/x-www-form-urlencoded',
                        'companyKey': companyKey || 'one-stand',
                    },
                    dataTypeString: 'json',
                    success: function(res){
                        var data;

                        try {
                            data = typeof res === 'string' ? JSON.parse(res) : res
                        } catch (e) {
                            data = {};
                        }

                        if (data.code == 200 || data.code == 204) {
                            resolve(data.data ? data.data : data.code);
                        } else if (data.code == 401 || data.code == 403) {
                            let param = $.formatParams(location.href);

                            localStorage.removeItem('info');
                            localStorage.removeItem('token');
                            location.href=location.origin + "/main/wx_login.html" + (param.company_key ? `?company_key=${param.company_key}` :'');
                            return;
                        } else{
                            reject(data);
                            layer.alert(data.message || '网络错误');
                        }
                    },
                    error: function(err){
                        reject(err)
                    },
                };
                var _setting = setting ? Object.assign({}, baseSetting, setting) : baseSetting;
                _this.ajax(_url, _setting);
            })
        },
        uploadFile: function(data){
            //生产地址: https://api.youdomain.com/file/uploadObjectOSS
            //测试地址: https://api.youdomain.com/file/uploadObjectOSS
            return fetch('https://api.youdomain.com/file/uploadObjectOSS', {
                method: 'POST',
                body: data
            }).then(res=>{
                return res.json();
            }).catch(res=>{
                return res.json();
            })
        },
        formatParams: function(url){
            var paramsStr = url.split('?')[1];

            if (!paramsStr) return {}

            var paramsArr = paramsStr.split('&');
            var paramsObj = {};

            paramsArr.map(function (param) {
                var tmp = param.split('=');
                paramsObj[tmp[0]] = tmp[1];
            });

            return paramsObj;
        },
        checkPhone(str) {
            if(!(/^1\d{10}$/.test(str))){
                return false;
            }else{
                return true
            }
        },
        checkEmail(str){
            if (/^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g.test(str)){
                return true;
            }else{
                return false;
            }
        },
        checkImgNameIsNumber(imgUrl){
            let urlImg = imgUrl.split(/\/|\./g);

            if (/^-?\d+$/.test(urlImg[urlImg.length - 2])) {
                return true;
            }else {
                return false;
            }
        },
    });

    if (typeof Vue === "function") {
        Vue.component('companyPosition', {
            name: 'companyPosition',
            template: '<div class="p-t-10 company-position">' +
                '                <span>' +
                '                ---{{info.companyName}}' +
                '                - {{info.roleId ? "BOSS": "员工"}}' +
                '               </span>' +
                '               <span>--- {{info.roleId ? "BOSS": "员工"}}</span>' +
                '        </div>' ,
            data() {
                return {
                    info: {},
                }
            },
            created(){
                let _this = this;

                try{
                    _this.info = JSON.parse(localStorage.getItem('info'));
                }catch (e) {
                    _this.info = {};
                }
            },
        });
        Vue.component('cSlider',{
                name: 'cSlider',
                props:{
                    current: {
                        type: [String, Number],
                        'default': '',
                    }
                },
                template: ' <ul id="sidebarnav">' +
                    '                    <li>' +
                    '                        <a class="waves-effect waves-dark" href="/" :class="{active: current == 1}" aria-expanded="false">' +
                    '                            <i class="icon-Monitor"></i>' +
                    '                            <span class="hide-menu">' +
                    '                                    工作台' +
                    '                                </span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li>' +
                    '                        <a class="waves-effect waves-dark" href="/main/add-client.html" :class="{active: current == 2}" aria-expanded="false">' +
                    '                            <i class="icon-Add-User"></i>' +
                    '                            <span class="hide-menu">' +
                    '                                    客户录入' +
                    '                                </span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li>' +
                    '                        <a class="waves-effect waves-dark" href="/main/customerManage.html" :class="{active: current == 3}" aria-expanded="false">' +
                    '                            <i class="icon-Administrator"></i>' +
                    '                            <span class="hide-menu">客户管理</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li v-show="isBoss">' +
                    '                        <a class="waves-effect waves-dark" href="/main/totalCustomer.html" :class="{active: current == 4}">' +
                    '                            <i class="icon-Affiliate"></i>' +
                    '                            <span class="hide-menu">总客户池</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                        <li v-show="isBoss">' +
                    '                        <a class="waves-effect waves-dark has-arrow" :class="{active: current == 11}">' +
                    '                            <i class="icon-Money"></i>' +
                    '                            <span class="hide-menu">优惠券管理</span>' +
                    '                        </a>' +
                    '                        <ul aria-expanded="false" class="collapse">' +
                    '                            <li><a href="/main/addCoupon.html"  :class="{active: current == 18}" >添加优惠券</a></li>' +
                    '                            <li><a href="/main/couponManage.html"  :class="{active: current == 19}" >优惠券列表</a></li>' +
                    '                            <li><a href="/main/couponRecord.html"  :class="{active: current == 20}">领取管理</a></li>' +
                    '                        </ul>' +
                    '                    </li>' +
                    '                    <li>' +
                    '                        <a class="waves-effect waves-dark has-arrow"  :class="{active: current == 5}">' +
                    '                            <i class="icon-Bank"></i>' +
                    '                            <span class="hide-menu">企业管理</span>' +
                    '                        </a>' +
                    '                        <ul aria-expanded="false" class="collapse">' +
                    '                            <li v-if="isBoss"><a href="/main/enterprise-info.html">企业信息</a></li>' +
                    '                            <li><a href="/main/prodControl.html">商品管理</a></li>' +
                    '                            <li><a href="/main/appointmentControl.html">预约管理</a></li>' +
                    '                            <li><a href="/main/memberList.html">员工列表</a></li>' +
                    '                        </ul>' +
                    '                    </li>' +
                    '                    <li>' +
                    '                        <a class="waves-effect waves-dark" href="/main/orderList.html" :class="{active: current == 6}" aria-expanded="false">' +
                    '                            <i class="icon-File-Chart"></i>' +
                    '                            <span class="hide-menu">订单管理</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li v-if="isBoss">' +
                    '                        <a class="waves-effect waves-dark" href="/main/adList.html" :class="{active: current == 10}" aria-expanded="false">' +
                    '                            <i class="icon-Photos"></i>' +
                    '                            <span class="hide-menu">广告图管理</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li v-show="isBoss">' +
                    '                        <a class="waves-effect waves-dark" href="/main/programManagement.html" :class="{active: current == 7}" aria-expanded="false">' +
                    '                            <i class="icon-Smartphone-3"></i>' +
                    '                            <span class="hide-menu">' +
                    '                                    小程序管理' +
                    '                                </span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li v-show="isBoss">' +
                    '                        <a class="waves-effect waves-dark has-arrow"  :class="{active: current == 8}">' +
                    '                            <i class="icon-Dice"></i>' +
                    '                            <span class="hide-menu">营销活动</span>' +
                    '                        </a>' +
                    '                        <ul aria-expanded="false" class="collapse">' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark has-arrow">' +
                    '                                       <span class="hide-menu">分销</span>' +
                    '                               </a>' +
                    '                               <ul aria-expanded="false" class="collapse">' +
                    '                                   <li v-if="info.isAgent == 1"><a href="/main/statistics.html">佣金记录</a></li> ' +
                    '                                   <li><a href="/main/distributionStatistics.html">分销统计</a></li> ' +
                    '                                   <li><a href="/main/distributionOrdersList.html">分销订单</a></li> ' +
                    '                                   <li><a href="/main/accountingRecords.html">到账流水</a></li> ' +
                    '                               </ul>' +
                    '                            </li>' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark has-arrow">' +
                    '                                   <span class="hide-menu">拼团</span>' +
                    '                               </a>' +
                    '                               <ul aria-expanded="false" class="collapse">' +
                    '                                   <li><a href="/main/assembleGoodsList.html">拼团商品列表</a></li> ' +
                    '                                   <li><a href="/main/joinAssembleList.html">参团列表</a></li> ' +
                    '                               </ul>' +
                    '                            </li>' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark has-arrow">' +
                    '                                   <span class="hide-menu">秒杀</span>' +
                    '                               </a>' +
                    '                               <ul aria-expanded="false" class="collapse">' +
                    '                                   <li><a href="/main/spikeGoodsList.html">秒杀商品列表</a></li> ' +
                    '                               </ul>' +
                    '                            </li>' +
                    '                        </ul>' +
                    '                    </li>' +
                    '                    <li v-if="info.isAgent == 1">' +
                    '                        <a class="waves-effect waves-dark" href="/main/agentManage.html" :class="{active: current == 9}" aria-expanded="false">' +
                    '                            <i class="icon-Temple"></i>' +
                    '                            <span class="hide-menu">代理企业</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    '                    <li v-show="isBoss">' +
                    '                        <a class="waves-effect waves-dark has-arrow"  :class="{active: current == 12}" aria-expanded="false">' +
                    '                            <i class="icon-Diploma-2"></i>' +
                    '                            <span class="hide-menu">获客文章管理</span>' +
                    '                        </a>' +
                    '                        <ul aria-expanded="false" class="collapse">' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark"  :class="{active: current == 17}"  href="/main/articlesManage.html">' +
                    '                                       <span class="hide-menu">获客文章</span>' +
                    '                               </a>' +
                    '                            </li>' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark" :class="{active: current == 16}"  href="/main/customerEssayType.html">' +
                    '                                   <span class="hide-menu">文章分类管理</span>' +
                    '                               </a>' +
                    '                            </li>' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark"  :class="{active: current == 15}"  href="/main/staffData.html">' +
                    '                                   <span class="hide-menu">员工数据</span>' +
                    '                               </a>' +
                    '                            </li>' +
                    '                            <li>' +
                    '                               <a class="waves-effect waves-dark" :class="{active: current == 14}"  href="/main/winCustomersData.html">' +
                    '                                   <span class="hide-menu">访客数据</span>' +
                    '                               </a>' +
                    '                            </li>' +
                    '                        </ul>' +
                    '                    </li>' +
                    '                    <li >' +
                    '                        <a class="waves-effect waves-dark" href="/main/videoManage.html" :class="{active: current == 13}" aria-expanded="false">' +
                    '                            <i class="icon-Video-5"></i>' +
                    '                            <span class="hide-menu">短视频管理</span>' +
                    '                        </a>' +
                    '                    </li>' +
                    // '                    <li>' +
                    // '                        <a class="waves-effect waves-dark has-arrow"  :class="{active: current == 9}">' +
                    // '                            <i class="icon-Bank"></i>' +
                    // '                            <span class="hide-menu">提现管理</span>' +
                    // '                        </a>' +
                    // '                        <ul aria-expanded="false" class="collapse">' +
                    // '                            <li><a href="/main/withdrawList.html?type=1">企业列表</a></li> ' +
                    // '                            <li><a href="/main/withdrawList.html?type=2">用户列表</a></li> ' +
                    // '                        </ul>' +
                    // '                    </li>' +
                    '                </ul>',
                data: function(){
                    return {
                        currentUrl: location.pathname,
                        info: {},
                        isBoss: false,
                    }
                },
                mounted: function() {
                    let _this = this;
                    $('#sidebarnav').AdminMenu();
                    try{
                        _this.info = JSON.parse(localStorage.getItem('info'));
                        _this.isBoss = this.info.roleId != 0;
                    }catch (e) {
                        _this.isBoss = false;
                    }
                }
            }
        );

        Vue.component('userHead', {
            name: 'userHead',
            data: function () {
                return {
                    info: {},
                }
            },
            template: '<ul class="navbar-nav my-lg-0">' +
                '                    <li class="nav-item dropdown u-pro">' +
                '                        <a class="nav-link dropdown-toggle waves-effect waves-dark profile-pic d-flex align-cen" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
                '                            <div class="img-bg-box w30 h30 v-middle braduis50p m-r-10" :style="`background-image: url(${info.avatarUrl})`" alt="user" ></div>' +
                '                            <span class="hidden-md-down">' +
                '                                    {{info.userName}}' +
                '                                    <i class="fa fa-angle-down"></i>' +
                '                                </span>' +
                '                        </a>' +
                '                        <div class="dropdown-menu dropdown-menu-right animated flipInY">' +
                '                            <ul class="dropdown-user">' +
                '                                <li @click="logout"><a href="#"><i class="fa fa-power-off"></i> 退出</a></li>' +
                '                            </ul>' +
                '                        </div>' +
                '                    </li>' +
                '                </ul>',
            created: function (){
                var _this = this;

                try{
                    _this.info = JSON.parse(localStorage.getItem('info'));
                }catch (e) {
                    _this.info = {};
                }
            },
            methods:{
                logout: function (){
                    localStorage.removeItem('token');
                    localStorage.removeItem('info');
                    location.href=location.origin + "/main/wx_login.html";
                }
            }
        });

        Vue.component('pageHelper', {
            name: 'pageHelper',
            template: '<div>' +
                '    <div class="page-helper" v-if="showPageHelper">' +
                '      <div class="page-list">' +
                '        <span v-if="!isSmall">共{{ totalPage }}页 / {{ totalCount }}条</span>' +
                '        <span v-if="!isSmall" class="page-item" @click="jumpPage(1)">首页</span>' +
                '        <span v-if="!isSmall" class="page-item" :class="{\'disabled\': currentPage === 1}"  @click="prevPage">上一页</span>' +
                '        <span class="page-ellipsis" v-if="showPrevMore" @click="showPrevPage">...</span>' +
                '        <span class="page-item" v-for="num in groupList" :class="{\'page-current\':currentPage===num}" :key="num"' +
                '              @click="jumpPage(num)">{{num}}</span>' +
                '        <span class="page-ellipsis" v-if="showNextMore" @click="showNextPage">...</span>' +
                '        <span v-if="!isSmall" class="page-item" :class="{\'disabled\': currentPage === totalPage}" @click="nextPage">下一页</span>' +
                '        <span v-if="!isSmall" class="page-item" @click="jumpPage(totalPage)">末页</span>' +
                '        <span v-if="!isSmall" class="ml20">跳至</span>' +
                '        <span v-if="!isSmall" class="page-jump-to"><input type="type" v-model="jumpPageNumber"></span>' +
                '        <span v-if="!isSmall">页</span>' +
                '        <span v-if="!isSmall" class="page-item jump-go-btn" @click="goPage(jumpPageNumber)">确定</span>' +
                '      </div>' +
                '    </div>' +
                '  </div>',
            data () {
                return {
                    currentPage: this.pageNumber,
                    currentSize: this.pageSizeArray[0],
                    jumpPageNumber: 1,
                    showPrevMore: false,
                    showNextMore: false
                }
            },
            props: {
                isSmall: {
                    type: Boolean,
                    default: false,
                },
                pageNumber: {   //当前页面
                    type: Number,
                    default: 1
                },
                pageSizeArray: {   //每页显示数量
                    type: Array,
                    default () {
                        return [10,20,30,50]
                    }
                },
                totalCount: {   //总条数
                    type: Number,
                    default: 1000
                },
                pageGroup: {   //连续页码个数
                    type: Number,
                    default: 5
                }
            },
            computed: {
                showPageHelper () {
                    return this.totalCount > 0
                },
                totalPage () {   //总页数
                    return Math.ceil(this.totalCount / this.currentSize);
                },
                groupList () {  //获取分页码
                    const groupArray = []
                    const totalPage = this.totalPage
                    const pageGroup = this.pageGroup
                    const _offset = (pageGroup - 1) / 2
                    let current = this.currentPage
                    const offset = {
                        start: current - _offset,
                        end: current + _offset
                    }
                    if (offset.start < 1) {
                        offset.end = offset.end + (1 - offset.start)
                        offset.start = 1
                    }
                    if (offset.end > totalPage) {
                        offset.start = offset.start - (offset.end - totalPage)
                        offset.end = totalPage
                    }
                    if (offset.start < 1) offset.start = 1
                    this.showPrevMore = (offset.start > 1)
                    this.showNextMore = (offset.end < totalPage)
                    for (let i = offset.start; i <= offset.end; i++) {
                        groupArray.push(i)
                    }
                    return groupArray
                }
            },
            methods: {
                prevPage () {
                    if (this.currentPage > 1) {
                        this.jumpPage(this.currentPage - 1)
                    }
                },
                nextPage () {
                    if (this.currentPage < this.totalPage) {
                        this.jumpPage(this.currentPage + 1)
                    }
                },
                showPrevPage() {
                    this.currentPage = this.currentPage - this.pageGroup > 0 ? this.currentPage - this.pageGroup : 1
                },
                showNextPage() {
                    this.currentPage = this.currentPage + this.pageGroup < this.totalPage ? this.currentPage + this.pageGroup : this.totalPage
                },
                goPage (jumpPageNumber) {
                    if(Number(jumpPageNumber) <= 0){
                        jumpPageNumber = 1
                    }if(Number(jumpPageNumber) >= this.totalPage){
                        jumpPageNumber = this.totalPage
                    }
                    this.jumpPage(Number(jumpPageNumber))
                },
                jumpPage (pageNumber) {
                    if (this.currentPage !== pageNumber) {  //点击的页码不是当前页码
                        this.currentPage = pageNumber;
                        this.$emit('change', {currentPage: this.currentPage, currentSize: this.currentSize});
                    }
                }
            },
            watch: {
                currentSize (newValue, oldValue) {
                    if(newValue !== oldValue){
                        if(this.currentPage >= this.totalPage){ //当前页面大于总页面数
                            this.currentPage = this.totalPage
                        }
                        this.$emit('change', {currentPage: this.currentPage, currentSize: this.currentSize})
                    }
                },
                pageNumber(){
                    this.currentPage = this.pageNumber;
                },
            },
        });

        Vue.component('selectMember', {
            name: 'selectMember',
            props: {
                isShow: {
                    type: Boolean,
                    default: false,
                },
                value : {
                    type: [String, Number],
                    default: '',
                },
                isShowShare:{
                    type: Boolean,
                    default: false,
                }
            },
            data(){
                return {
                    page: 1,
                    total: 0,
                    memberList: [],
                    searchKey: '',
                    chooseCardId: '',
                    customerState: 1,
                }
            },
            template: ' <div v-if="isShow" class="position-fixed bg000_3 w100p h100p zindex99 left0 top0">' +
                '        <div class="bgfff w629 h750 oyauto position-absolute left0 top0 right0 bottom0 mauto p-t-30 p-b-50">' +
                ' <div class="disflex justify-content-center" v-if="isShowShare">' +
                '        <p @click="customerState=2">' +
                '            <span class="w16 h16 bradius4 bced d-inline-block mdi position-relative top3"' +
                '                  :class="customerState==2 ? \'mdi-check checks\':\'\'"' +
                '                  ></span>' +
                '            移至共享' +
                '        </p>' +
                '        <p class="m-l-40" @click="customerState=1">' +
                '            <span class="w16 h16 bradius4 bced d-inline-block mdi position-relative top3"' +
                '                  :class="customerState==1 ? \'mdi-check checks\':\'\'"' +
                '                  ></span>' +
                '            选择移交人' +
                '        </p>' +
                '    </div>'+
                '       <p class="fs16 textc m-b-49" v-else>移至成员</p>' +
                // '            <div class="d-flex jscen align-cen p-b-32">' +
                // '                <input type="text" class="p-l-23 phgray lh38 h38 w241 bradius4 bef0" placeholder="请输入姓名或电话用户">' +
                // '                <span class="p-l-20 p-r-20 cfff bgblue bradius4 lh30 m-l-20" @click="getMember">查询</span>' +
                // '            </div>' +
                '            <div class="bef0 lh45 c26 fs14 w420 border-top-0  mauto">' +
                '                <div class="d-flex jsbet p-l-15 p-r-15  align-cen btef0 member-item" v-for="(v,k) in memberList" :key="k">' +
                '                    <span class="diy-radio" :class="chooseCardId == v.cardId ? \'check\':\'\'" @click.stop="checkTap(v.cardId)"></span>' +
                '                    <img :src="v.logo || \'https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/crm/card1_user.png\'" alt="" class="w30 h30 braduis50p">' +
                '                    <span class="name text">{{v.name}}</span>' +
                '                    <span class="phone">{{v.phone}}</span>' +
                '                </div>' +
                '            </div>' +
                '            <div class="position-absolute bottom50 w100p">' +
                '                <!--分页-->' +
                '                <div class="d-flex p-b-30 jscen">' +
                '                <page-helper :page-number="page" :total-count="total" @change="jumpPage" :isSmall="true"></page-helper>'+
                '                </div>' +
                '                <div class="mauto d-flex jscen fs14 lh40">' +
                '                    <span class="w85 textc cblue bblue bradius4 m-r-19" @click="cancel">取消</span>' +
                '                    <span class="bgblue cfff w85 textc bradius4" @click="confirm">确定</span>' +
                '                </div>' +
                '            </div>' +
                '        </div>' +
                '    </div>',
            mounted(){
                this.getMember();
            },
            methods:{
                jumpPage({currentPage}){
                    this.page = currentPage;
                    this.getMember();
                },
                checkTap (cardId) {
                    this.chooseCardId = cardId;
                    this.$emit('input', cardId);
                },
                getMember(){
                    $.cAjax('/crmPc/customer/getCompanyStaffList', {
                        data: {
                            pageNum: this.page,
                            // asd: this.searchKey,
                        }
                    }).then((res)=> {
                        this.memberList = res.list;
                        this.total = res.totalNumber
                    });
                },
                confirm(){
                    if (this.customerState == 1){
                        this.$emit('confirm');
                    }else{
                        this.$emit('confirm-to-share', this.customerState);
                    }

                },
                cancel() {
                    this.$emit('cancel');
                },
            }
        });

        Vue.component('selectGoods', {
            name: 'selectGoods',
            props: {
                isShow: {
                    type: Boolean,
                    default: false,
                },
            },
            data(){
                return {
                    page: 1,
                    total: 0,
                    goodsList: [],
                    chooseRow: null,
                }
            },
            template: '<div class="position-fixed bg000_3 w100p h100p zindex99 left0 top0">' +
                '            <div class="custom-dialog">' +
                '                <p class="fs16 textc m-b-30">选择商品</p>' +
                '                <table class="align-cen-table textc display nowrap table table-hover table-bordered bgf6f9fa m-b-20">' +
                '                    <thead>' +
                '                    <tr>' +
                '                        <th></th>' +
                '                        <th>产品ID</th>' +
                '                        <th class="w20p">产品</th>' +
                '                        <th>分类</th>' +
                '                        <th>价格</th>' +
                '                        <th>库存</th>' +
                '                        <th>总销量</th>' +
                '                        <th>发布时间</th>' +
                '                    </tr>' +
                '                    </thead>' +
                '                    <tbody class="bgfff">' +
                '                    <tr v-for="(v,k) in goodsList" :key="k" class="curpointer" >' +
                '                        <td>' +
                '                            <span class="diy-radio dis-inline-block" :class="chooseRow == v ? \'check\':\'\'" @click.stop="chooseRow=v"></span>' +
                '                        </td>' +
                '                        <td v-html="v.goodsId"></td>' +
                '                        <td v-html="v.goodsName" class="w20p"></td>' +
                '                        <td v-html="v.goodsTypeName"></td>' +
                '                        <td>{{(v.price/100).toFixed(2)}}</td>' +
                '                        <td v-html="v.goodsNum"></td>' +
                '                        <td v-html="v.dealNum"></td>' +
                '                        <td>{{v.createTime | formatDate(\'yyyy/MM/dd hh:mm\')}}</td>' +
                '                    </tr>' +
                '                    </tbody>' +
                '                </table>' +
                '                <div class="w100p">' +
                '                    <page-helper :page-number="page" :total-count="total" @change="jumpPage" :isSmall="true"></page-helper>' +
                '                    <div class="mauto d-flex jscen fs14 lh40 m-t-20">' +
                '                        <span class="w85 textc cblue bblue bradius4 dis-inline-block m-r-19" @click="cancel">取消</span>' +
                '                        <span class="bgblue cfff w85 textc bradius4 dis-inline-block" @click="confirm">确定</span>' +
                '                    </div>' +
                '                </div>' +
                '            </div>' +
                '        </div>',
            mounted(){
                this.getGoodsList();
            },
            methods:{
                jumpPage({currentPage}){
                    this.page = currentPage;
                    this.getGoodsList();
                },
                getGoodsList() {
                    $.cAjax('/crmPc/companyGoods/getGoodsInfoPC', {
                        data: {
                            pageNum: 1,
                        }
                    }).then((data) =>{
                        if (data) {
                            var pageInfo = JSON.parse(data.pageInfo);
                            this.goodsList = pageInfo.list || [];
                        }
                    }).catch(function (err) {

                    });
                },
                confirm(){
                    this.$emit('confirm', this.chooseRow);
                },
                cancel() {
                    this.$emit('cancel');
                },
            }
        });

        Vue.component('prevGoods', {
            name: 'prevGoods',
            props: {
                isShow:{
                    type: Boolean,
                    default: false,
                },
                prod_imgs: {
                    type: Array,
                    default (){return []},
                },
                prodSize: {
                    type: Array,
                    default(){return []},
                },
                edit_html: {
                    type: String,
                    default: '',
                },
                goodsName:{
                    type: String,
                    default: '',
                },
                isFormatMoney: {
                    type: Boolean,
                    default: false,
                }
            },
            data(){
                return {
                    type_index_1:0,
                    type_index_2:0,
                    type_id_1: 0,
                }
            },
            template: '<div class="bg000_3 w100p h100p left0 top0 position-fixed zindex10002" id="prev_modal" v-if="isShow" @click="previewTap($event)">' +
                '        <div class="preview-inner">' +
                '            <div class="w100p h100p bgf5f6 oyauto scrollbar_none position-relative p-b-51">' +
                '                <div id="carouselExampleControls" class="carousel slide w100p h355" data-ride="carousel">' +
                '                    <div class="carousel-inner" role="listbox">' +
                '                        <div class="carousel-item" v-for="(img,idx) in prod_imgs" :class="{active:idx ==0}">' +
                '                            <div class="container">' +
                '                                <div class="d-block img-fluid goods-img" :style="`background-image:url(${img})`"></div>' +
                '                            </div>' +
                '                        </div>' +
                '                    </div>' +
                '                    <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a>' +
                '                    <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a>' +
                '                </div>' +
                '                <div class="bgfff p-l-16 p-r-15 p-b-15 m-b-10">' +
                '                    <p class="lh45 m-b-0">' +
                '                        <span class="text-warning fs20 m-r-10">¥{{goodsPrice}}</span>' +
                '                    </p>' +
                '                    <div class="d-flex jsbet">' +
                '                        <p class="over_2 fs14 c38 fbold flex1">' +
                '                            {{goodsName}}' +
                '                        </p>' +
                '                        <div class=\'w46 p-l-30 bgfff contentbox text-right disflex align-cen \' >' +
                '                            <img src="https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/share.png" alt="" class="w15 h15 m-r-7">' +
                '                            <b class="fs12 ca8">分享</b>' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '                <!--规格-->' +
                '                <div class="p-l-16 p-r-16 bgfff p-t-16">' +
                '                    <p class="fs14 ca8 pb10">类型</p>' +
                '                    <div class="pb15">' +
                '                        <div v-for="(v,k) in prodSize"' +
                '                             class="fs12 c38  p-l-10 p-r-10 m-r-10 m-b-10 bgf5f6 disinblock lh30 bradius3 bf5f6 size_item dis-inline-block"' +
                '                             :class="type_id_1 == v.specId ? \'active\' : \'\' "' +
                '                             @click="type_tap_1(v.specId,k)">{{v.specName}}</div>' +
                '                        <p class="fs14 ca8 pb10">规格</p>' +
                '                        <div v-if="prodSize[type_index_1] && prodSize[type_index_1].list">' +
                '                            <div v-for="(v2,k2) in prodSize[type_index_1].list"' +
                '                                 class="fs12 c38  p-l-10 p-r-10 m-r-10 m-b-10 bgf5f6 disinblock lh30 bradius3 bf5f6 size_item dis-inline-block"' +
                '                                 :class="prodSize[type_index_1].selectId == v2.specId ? \'active\' : \'\' "' +
                '                                 @click="type_tap(type_index_1,k2,v2.specId )">{{v2.specAttribute}}</div>' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '                <!--- 宝贝详情 --->' +
                '                <div>' +
                '                    <p class="lh43 textc fs14 ca8 m-b-0">- 宝贝详情 -</p>' +
                '                    <div class="h270 bgfff diy_prod_detail" v-html="edit_html" ></div>' +
                '                </div>' +
                '                <p class="lh43 textc fs12 ca8 m-b-0">- 到底了，看看其他的吧 -</p>' +
                '            </div>' +
                '            <!--bottom-->' +
                '            <!--购买-->' +
                '            <div class=" position-absolute bottom left0 w100p ">' +
                '                <div class="w100p d-flex bte8">' +
                '                    <div class="d-flex flex1 bgfff textc">' +
                '                        <div class="w33p p-t-7">' +
                '                            <img src="https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/prod_select.png" alt="" class="w20 h20">' +
                '                            <b class="cblue fs12 textc m-t-_2 d-block">产品</b>' +
                '                        </div>' +
                '                        <div class="w33p p-t-7" >' +
                '                            <img src="https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/tel_gray.png" alt="" class="w20 h20">' +
                '                            <b class="ca8 fs12 textc m-t-_2 d-block">通话</b>' +
                '                        </div>' +
                '                        <div class="w33p p-t-7" >' +
                '                            <img src="https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/like_gray.png" alt="" class="w20 h20">' +
                '                            <b class="fs12 textc m-t-_2 ca8 d-block">收藏</b>' +
                '                        </div>' +
                '                    </div>' +
                '                    <div class="w220 disflex textc fs16 cfff p-r-15 p-t-5 p-b-5 borderbox bgfff lh40">' +
                '                        <span class="w50p bg_line_yellow add_to_card" >加入购物车</span>' +
                '                        <span class="w50p bg_line_orange buy_now m-l-_1" >立即购买</span>' +
                '                    </div>' +
                '                </div>' +
                '            </div>' +
                '        </div>' +
                '    </div>',
            mounted(){

            },
            methods:{
                previewTap(e){
                    if(e.target.id == 'prev_modal'){
                        this.$emit('close');
                        $('body').css('overflow','');
                    }
                },
                type_tap_1(id_1 , index_1){//点击一级分类
                    this.type_id_1 = id_1 ;
                    this.type_index_1 = index_1 ;
                },
                type_tap(index_1,index_2 , id) {
                    this.prodSize[index_1].selectId = id;
                    this.type_index_2 = index_2;
                    let price = this.prodSize[index_1].goodSpecModelList[index_2].price;
                    this.goodsPrice = price ;
                    this.typeId = id ;
                },
            },
            computed:{
                goodsPrice(){
                    let moeny = this.prodSize[this.type_index_1].goodSpecModelList[this.type_index_2].price || 0.00;
                    if(this.isFormatMoney){
                        moeny = (moeny/100).toFixed(2)
                    }
                    return moeny;
                }
            },
            watch:{
                prodSize:{
                    handler(){
                        let price;
                        try {
                            price = this.prodSize[this.index_1].goodSpecModelList[this.index_2].price
                        }catch (e) {
                            price = 0;
                        }
                        this.goodsPrice = price || 0;
                    },
                    deep: true,
                }
            }
        });

        Vue.mixin({
            data:function(){
                return{
                    projectName: configInfo && configInfo.projectName|| "壹脉",
                    //兼容oem配置 这里需要注释
                    // projectPhone: configInfo && configInfo.projectPhone|| "",
                }
            },
            beforeMount:function() {
                this.$nextTick(function(){
                    // document.title = configInfo.projectTitle || "壹脉智能CRM"
                })
            },
            filters: {
                getStatus: function (companyCard) {
                    if (companyCard.endTime) {
                        let endTime = new Date(companyCard.endTime).getTime();
                        let nowTime = new Date().getTime();
                        if (endTime > nowTime) {
                            return "正常" // 未到期返回''
                        } else {
                            return "已到期"
                        }
                    } else {
                        return ""
                    }
                },
                getStatusByTimestamp: function (timestamp) {
                    let nowTime = new Date().getTime();
                    if (timestamp > nowTime) {
                        return "已授权"
                    } else {
                        return "已到期"
                    }
                },
                formatMoney: function(money) {
                    return money ? (money/100).toFixed(2) : 0;
                },
                formatDate: function(date, fmt){
                    if (!date) return fmt.replace(/[a-z]|[A-Z]/g, '-');

                    date = date instanceof Date ? date : new Date(date);

                    var o = {
                        "M+" : date.getMonth()+1,                 //月份
                        "d+" : date.getDate(),                    //日
                        "h+" : date.getHours(),                   //小时
                        "m+" : date.getMinutes(),                 //分
                        "s+" : date.getSeconds(),                 //秒
                        "q+" : Math.floor((date.getMonth()+3)/3), //季度
                        "S"  : date.getMilliseconds()             //毫秒
                    };
                    if(/(y+)/.test(fmt))
                        fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
                    for(let k in o){
                        if(new RegExp("("+ k +")").test(fmt)){
                            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                        }
                    }
                    return fmt;
                },
            },
        })
    }
});
